package com.xposed.openfire.smack;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.xposed.openfire.smack.utils.LogUtils;
import com.xposed.openfire.smack.xmpp.XmppConnection;


import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class UserLoginActivity extends AppCompatActivity {

    @BindView(R.id.edit_user_name)
    TextInputEditText editUserName;
    @BindView(R.id.edit_password)
    TextInputEditText editPassword;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_login);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.btn_user_login, R.id.btn_user_logon})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_user_login:
                boolean isLogin = XmppConnection.getInstance().userLogin(editUserName.getText().toString(), editPassword.getText().toString());
                if (isLogin) {
                    Intent intent = new Intent(this, MainActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    Toast.makeText(this, "登录失败", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_user_logon:
                LogUtils.e("" + XmppConnection.getInstance().getHostedRoom());
//                Intent intent = new Intent(this, UserLogonActivity.class);
//                startActivity(intent);
                break;
            default:
                break;
        }
    }
}
